console.log("Hello World!");
const crypto = require('crypto'); 
//生成签名
//Signature=md5(AppId + SignatureNonce + ServerSecret + Timestamp)
function GenerateUASignature(appId, signatureNonce, serverSecret, timeStamp){
    const hash = crypto.createHash('md5'); //规定使用哈希算法中的MD5算法
    var str = appId + signatureNonce + serverSecret + timeStamp;
    hash.update(str);
    //hash.digest('hex')表示输出的格式为16进制
    return hash.digest('hex');
}

var signatureNonce = crypto.randomBytes(8).toString('hex');
//使用你的appId和serverSecret
var appId = 1048172193;
var serverSecret = "b86af07b8a280de3ed39fe2ab30b9b8f";
var timeStamp = Math.round(Date.now()/1000);
var sig = GenerateUASignature(appId, signatureNonce, serverSecret, timeStamp)

const request = require('request');

var url = `https://rtc-api.zego.im/?Action=StopMix&RoomId[]=2&AppId=${appId}&SignatureNonce=${signatureNonce}&Timestamp=${timeStamp}&Signature=${sig}&SignatureVersion=2.0&IsTest=false`
var body = {
  'TaskId':'123',
  'Sequence':123,
  'UserId':'123'
}


request({
  url: url,
  method: 'POST',
  json: true,
  headers: {
      'content-type': 'application/json'
  },
  body: body
}, function(error, response, body){
  console.log(error)
  console.log(response.statusCode)
  if(!error && response.statusCode === 200){
      console.log(body.Data)
  }
})
